package org.apache.lucene.index;

import java.io.IOException;
import java.util.Collection;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldSelector;

/**
 * IndexReader encapsulating a TagIndexSnapshot
 *
 */
public class TagIndexReader extends IndexReader {
  private TagIndexSnapshot tagIndexSnapshot;

  public TagIndexReader(TagIndexSnapshot tagIndexSnapshot) {
    this.tagIndexSnapshot = tagIndexSnapshot;
  }
  
  public boolean isDeleted(int n) {
    if (tagIndexSnapshot.deletedDocs != null && tagIndexSnapshot.deletedDocs.get(n)) {
      return true;
    } else {
      return false;
    }
  }
  
  protected void doClose() throws IOException {
    tagIndexSnapshot.close();
  }
  
  protected void doCommit() throws IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }
  
  public int docFreq(Term t) throws IOException {
    TagTermInfo tti = tagIndexSnapshot.getTagTermInfo(t);
    if (tti != null) return tti.docFreq;
    return 0;
  }
  
  public void norms(String field, byte[] bytes, int offset) throws IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }
  
  
  
  public boolean hasDeletions() {
    return tagIndexSnapshot.hasDeletions();
  }
  
  protected void doUndeleteAll() throws CorruptIndexException, IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }
  
  public byte[] norms(String field) throws IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }
  
  public TermDocs termDocs() throws IOException {
    return tagIndexSnapshot.termDocs();
  }
  
  public TermPositions termPositions() throws IOException {
    return tagIndexSnapshot.termDocs();
  }
  
  protected void doDelete(int docNum) throws CorruptIndexException, IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }
  
  protected void doSetNorm(int doc, String field, byte value) throws CorruptIndexException, IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }
  
  public TermEnum terms() throws IOException {
    return tagIndexSnapshot.terms();
  }
  
  public TermEnum terms(Term term) throws IOException {
    return tagIndexSnapshot.terms(term);
  }

  // TODO: should return only fields for the snapshot
  public Collection getFieldNames(FieldOption fldOption) {
    TagFieldInfos tagFieldInfos = tagIndexSnapshot.tagIndex.getTagFieldInfos();
    return tagFieldInfos.fieldNames();
  }

  public Document document(int n, FieldSelector fieldSelector) throws CorruptIndexException, IOException {
    return tagIndexSnapshot.getDocument(n, fieldSelector);
  }

  public int maxDoc() {
    return tagIndexSnapshot.tagIndex.maxDoc;
  }

  public int numDocs() {
    return tagIndexSnapshot.numDocs();
  }

  public void getTermFreqVector(int docNumber, TermVectorMapper mapper) throws IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }

  public void getTermFreqVector(int docNumber, String field, TermVectorMapper mapper) throws IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }

  public TermFreqVector[] getTermFreqVectors(int docNumber) throws IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }

  public TermFreqVector getTermFreqVector(int docNumber, String field) throws IOException {
    throw new UnsupportedOperationException("This reader does not support this method.");
  }
}
